#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
using namespace std;

const ll N = 1e6 + 10, INF = 1e15;

ll n, m;
ll p[N];

bool check(vector<vector<ll>>& a, ll w)
{
    vector<vector<ll>> b(n + 1, vector<ll>(m + 1, -INF));
    b[0][1] = b[1][0] = w;
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++) {
            b[i][j] = max(b[i - 1][j], b[i][j - 1]) + a[i][j] - p[i + j - 1];
            if (b[i][j] < 0) b[i][j] = -INF;
        }
    return b[n][m] >= 0;
}

void solve()
{
    cin >> n >> m;
    vector<vector<ll>> a(n + 1, vector<ll>(m + 1));
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++)
            cin >> a[i][j];
    for (ll i = 1;i <= n + m - 1;i++) cin >> p[i];
    ll l = 0, r = 1e15;
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (check(a, mid)) r = mid;
        else l = mid + 1;
    }
    cout << r;
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}